home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1
/
Ian and Stuart's One (Australia).iso
/
Australasian Legends
/
Commercial
/
Rainbow Hill
/
MacDOS™ 2.0.0
/
filters
/
filter projects
/
filters.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-27
|
3KB
|
116 lines
/*
* filters.c Some MacDOS filters.
*
* Released MacDOS 1.0.1a on 94/01/31
* 94/05/27 File created by copying filter.c
* 94/05/27 First version completed
*
*--------------------------------------------------------------------------------------------------
* Copyright © 1994 by Rainbow Hill Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <Errors.h>
#include "pipe.h"
#define doNothing 0
#define multiplyLines 1
#define countLines 2
#define doThis 0 /* adjust this value to select the filtering */
static pipeParmsFun_t HandleParameters;
/*
* global variable definitions
*/
#if doThis == multiplyLines
static short nTimes;
#endif
main() {
OSErr os_err;
unsigned char inBuff[pipeSize];
unsigned char outBuff[pipeSize];
/* initialisation */
MaxApplZone();
InitGraf(&thePort);
InitWindows();
InitDialogs(0L);
InitCursor();
/* initialise the incoming pipe */
PipeInit(HandleParameters);
/* keep getting records from the master as long as no error occurs */
while (true) {
/* wait to receive the next record */
PipePoll(inBuff);
/*
* filtering
*/
# if doThis == doNothing
{ /* just copy the input to the output */
PipeSendData(inBuff);
}
# elif doThis == multiplyLines
{ /* repeates the input lines a fixed number of times */
short k;
for (k = nTimes; k > 0; k--) PipeSendData(inBuff);
}
# elif doThis == countLines
{ /* count the lines and send out the number when receiving an empty line */
static long k = 0L;
if (inBuff[0] > 0) {
k++;
PipeSendData("\p");
}
else {
NumToString(k, inBuff);
inBuff[inBuff[0] + 1] = '\r';
inBuff[0]++;
PipeSendData(inBuff);
}
}
# endif
}
} /* main */
/*------------------------------------------------------------------------------ HandleParameters */
static OSErr HandleParameters(unsigned char *parms) {
# if doThis == multiplyLines
{
long aLong;
StringToNum(parms, &aLong);
if (aLong <= 0L)
nTimes = 1;
else
nTimes = (short)aLong;
}
# endif
return (noErr);
} /* HandleParameters */